home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / moni / systemviewer.lha / SysFonts.c < prev    next >
C/C++ Source or Header  |  2001-03-13  |  10KB  |  413 lines

  1. /****h* SysFonts [1.0] *************************************************
  2. *
  3. * NAME
  4. *    SysFonts
  5. *
  6. * DESCRIPTION
  7. *    Display the contents of ENVARC:sys/font.prefs
  8. *
  9. *  GUI Designed by : Jim Steichen
  10. ************************************************************************
  11. *
  12. */
  13.  
  14. #include <string.h>
  15.  
  16. #include <exec/types.h>
  17.  
  18. #include <intuition/intuition.h>
  19. #include <intuition/classes.h>
  20. #include <intuition/classusr.h>
  21. #include <intuition/gadgetclass.h>
  22.  
  23. #include <libraries/gadtools.h>
  24. #include <libraries/asl.h>        // For the Font Requester.
  25. #include <libraries/iffparse.h>
  26.  
  27. #include <graphics/displayinfo.h>
  28. #include <graphics/gfxbase.h>
  29. #include <graphics/text.h>
  30.  
  31. #include <prefs/font.h>           // struct FontPrefs
  32.  
  33. #include <clib/exec_protos.h>
  34. #include <clib/intuition_protos.h>
  35. #include <clib/gadtools_protos.h>
  36. #include <clib/graphics_protos.h>
  37. #include <clib/utility_protos.h>
  38. #include <clib/diskfont_protos.h>
  39.  
  40. #include "CPGM:GlobalObjects/CommonFuncs.h"
  41.  
  42. #include "SysLists.h"
  43.  
  44. #define FLV     0
  45. #define Update  1
  46. #define Cancel  2
  47. #define Remove  3
  48. #define Change  4
  49.  
  50. #define SF_CNT  5
  51.  
  52. PRIVATE char ver[] = "$VER: SysFonts 1.0 (13-Mar-2001) by J.T. Steichen";
  53.  
  54. PRIVATE struct TextFont     *SFFont  = NULL;
  55. PRIVATE struct Window       *SFWnd   = NULL;
  56. PRIVATE struct Gadget       *SFGList = NULL;
  57. PRIVATE struct IntuiMessage  SFMsg;
  58. PRIVATE struct Gadget       *SFGadgets[ SF_CNT ];
  59.  
  60. PRIVATE UWORD  SFLeft   = 0;
  61. PRIVATE UWORD  SFTop    = 16;
  62. PRIVATE UWORD  SFWidth  = 635;
  63. PRIVATE UWORD  SFHeight = 230;
  64. PRIVATE UBYTE *SFWdt    = (UBYTE *) "System Fonts Info:";
  65.  
  66. PRIVATE char ltitle[] = "Cnt Y  X  Style Flags LoChar HiChar Type  Name";
  67. PRIVATE char fmt[]    = "%3d %3d %3d %s %08LX %3d %3d %s %s";
  68.  
  69. /*
  70.    ENVARC:sys/font.prefs 1st chunk: 'FORM' size 'PREF' 'PRHD'
  71.    ENVARC:sys/font.prefs contains 3 'FONT' chunks with the following in them:
  72.  
  73. struct FontPrefs {
  74.  
  75.    LONG            fp_Reserved[3];
  76.    UWORD           fp_Reserved2;
  77.    UWORD           fp_Type;       // 0, 1, 0r 2
  78.    UBYTE           fp_FrontPen;
  79.    UBYTE           fp_BackPen;
  80.    UBYTE           fp_DrawMode;
  81.    struct TextAttr fp_TextAttr;
  82.    BYTE            fp_Name[ FONTNAMESIZE ]; // FONTNAMESIZE = 128
  83. };
  84.  
  85. */
  86.  
  87. PRIVATE struct bfont {
  88.  
  89.    struct TextAttr *bf_TTextAttr;
  90.    struct TextFont *bf_TextFont;   
  91. };
  92.  
  93. PRIVATE struct TextAttr iconTextAttr    = { 0, };
  94. PRIVATE struct TextAttr defaultTextAttr = { 0, };
  95. PRIVATE struct TextAttr screenTextAttr  = { 0, };
  96.     
  97. PRIVATE struct TextFont iconTextFont    = { 0, };
  98. PRIVATE struct TextFont defaultTextFont = { 0, };
  99. PRIVATE struct TextFont screenTextFont  = { 0, };
  100.  
  101. PRIVATE struct bfont IconFont    = { &iconTextAttr,    &iconTextFont    };
  102. PRIVATE struct bfont DefaultFont = { &defaultTextAttr, &defaultTextFont };
  103. PRIVATE struct bfont ScreenFont  = { &screenTextAttr,  &screenTextFont  };
  104.     
  105. // --------------------------------------------------------------------
  106.  
  107. #define NODELENGTH 80
  108. #define MAXNODES   10
  109.  
  110. PRIVATE UBYTE NodeStrs[ MAXNODES * NODELENGTH ] = "";
  111.  
  112. PRIVATE struct Node FLV0Nodes[] = { 0, };
  113. PRIVATE struct List FLV0List    = { 0, };
  114.  
  115. // --------------------------------------------------------------------
  116.  
  117. PRIVATE UWORD SFGTypes[] = {
  118.  
  119.    LISTVIEW_KIND, BUTTON_KIND, BUTTON_KIND,
  120.    BUTTON_KIND, BUTTON_KIND
  121. };
  122.  
  123. PRIVATE int FLVClicked(    int whichitem );
  124. PRIVATE int UpdateClicked( int dummy     );
  125. PRIVATE int CancelClicked( int dummy     );
  126. PRIVATE int RemoveClicked( int dummy     );
  127. PRIVATE int ChangeClicked( int dummy     );
  128.  
  129. PRIVATE struct NewGadget SFNGad[] = {
  130.  
  131.      2,   3, 627, 200,                NULL, NULL, FLV,    0,
  132.    NULL, (APTR) FLVClicked,
  133.  
  134.      4, 205,  71,  17, (UBYTE *) "_Update", NULL, Update, PLACETEXT_IN, 
  135.    NULL, (APTR) UpdateClicked,
  136.  
  137.    554, 205,  72,  17, (UBYTE *) "_Cancel", NULL, Cancel, PLACETEXT_IN,
  138.    NULL, (APTR) CancelClicked,
  139.  
  140.     82, 205,  71,  17, (UBYTE *) "Remove",  NULL, Remove, PLACETEXT_IN,
  141.    NULL, (APTR) RemoveClicked,
  142.  
  143.    155, 205,  71,  17, (UBYTE *) "Change",  NULL, Change, PLACETEXT_IN,
  144.    NULL, (APTR) ChangeClicked
  145. };
  146.  
  147. PRIVATE ULONG SFGTags[] = {
  148.  
  149.    GTLV_ShowSelected, TRUE, LAYOUTA_Spacing, 2, TAG_DONE,
  150.  
  151.    GT_Underscore,  '_', TAG_DONE,
  152.    GT_Underscore,  '_', TAG_DONE,
  153.  
  154.    GA_Disabled,   TRUE, TAG_DONE,
  155.  
  156.    TAG_DONE
  157. };
  158.  
  159. // ----------------------------------------------------------------
  160.  
  161. PRIVATE void CloseSFWindow( void )
  162. {
  163.    if (SFWnd != NULL)
  164.       {
  165.       CloseWindow( SFWnd );
  166.       SFWnd = NULL;
  167.       }
  168.  
  169.    if (SFGList != NULL)
  170.       {
  171.       FreeGadgets( SFGList );
  172.       SFGList = NULL;
  173.       }
  174.  
  175.    if (SFFont != NULL)
  176.       {
  177.       CloseFont( SFFont );
  178.       SFFont = NULL;
  179.       }
  180.  
  181.    return;
  182. }
  183.  
  184. PRIVATE int SFCloseWindow( void )
  185. {
  186.    CloseSFWindow();
  187.    return( (int) FALSE );
  188. }
  189.  
  190. // ----------------------------------------------------------------
  191.  
  192. PRIVATE int ReadFontPrefs( void )
  193. {
  194.    FILE *infile = fopen( "ENVARC:sys/font.prefs", "r" );
  195.  
  196.    fclose( infile );
  197.    return( 0 );
  198. }
  199.  
  200. // ----------------------------------------------------------------
  201.  
  202. PRIVATE int FLVClicked( int whichitem )
  203. {
  204.    return( (int) TRUE );
  205. }
  206.  
  207. PRIVATE int UpdateClicked( int dummy )
  208. {
  209.    return( (int) TRUE );
  210. }
  211.  
  212. PRIVATE int RemoveClicked( int dummy )
  213. {
  214.    return( (int) TRUE );
  215. }
  216.  
  217.  
  218. PRIVATE int ChangeClicked( int dummy )
  219. {
  220.    return( (int) TRUE );
  221. }
  222.  
  223. PRIVATE int CancelClicked( int dummy )
  224. {
  225.    return( SFCloseWindow() );
  226. }
  227.  
  228. // ----------------------------------------------------------------
  229.  
  230. PRIVATE int OpenSFWindow( void )
  231. {
  232.    struct NewGadget  ng;
  233.    struct Gadget    *g;
  234.    UWORD             lc, tc;
  235.    UWORD             wleft = SFLeft, wtop = SFTop, ww, wh;
  236.  
  237.    ComputeFont( Scr, Font, &CFont, SFWidth, SFHeight );
  238.  
  239.    ww = ComputeX( CFont.FontX, SFWidth );
  240.    wh = ComputeY( CFont.FontY, SFHeight );
  241.  
  242.    if ((wleft + ww + CFont.OffX + Scr->WBorRight) > Scr->Width)
  243.       wleft = Scr->Width - ww;
  244.  
  245.    if ((wtop + wh + CFont.OffY + Scr->WBorBottom) > Scr->Height)
  246.       wtop = Scr->Height - wh;
  247.  
  248.    if ((SFFont = OpenDiskFont( Font )) == NULL)
  249.       return( -5 );
  250.  
  251.    if ((g = CreateContext( &SFGList )) == NULL)
  252.       return( -1 );
  253.  
  254.    for (lc = 0, tc = 0; lc < SF_CNT; lc++)
  255.       {
  256.       CopyMem( (char *) &SFNGad[lc], (char *) &ng, 
  257.                (long) sizeof( struct NewGadget )
  258.              );
  259.  
  260.       ng.ng_VisualInfo = VisualInfo;
  261.       ng.ng_TextAttr   = Font;
  262.  
  263.       ng.ng_LeftEdge   = CFont.OffX + ComputeX( CFont.FontX, 
  264.                                                 ng.ng_LeftEdge
  265.                                               );
  266.  
  267.       ng.ng_TopEdge    = CFont.OffY + ComputeY( CFont.FontY, 
  268.                                                 ng.ng_TopEdge
  269.                                               );
  270.  
  271.       ng.ng_Width      = ComputeX( CFont.FontX, ng.ng_Width );
  272.       ng.ng_Height     = ComputeY( CFont.FontY, ng.ng_Height );
  273.  
  274.       SFGadgets[lc] = g = CreateGadgetA( (ULONG) SFGTypes[lc], 
  275.                             g, 
  276.                             &ng, 
  277.                             (struct TagItem *) &SFGTags[tc] );
  278.  
  279.       while (SFGTags[tc] != NULL)
  280.          tc += 2;
  281.  
  282.       tc++;
  283.  
  284.       if (g == NULL)
  285.          return( -2 );
  286.       }
  287.  
  288.    if ((SFWnd = OpenWindowTags( NULL,
  289.  
  290.                  WA_Left,        wleft,
  291.                  WA_Top,         wtop,
  292.                  WA_Width,       ww + CFont.OffX + Scr->WBorRight,
  293.                  WA_Height,      wh + CFont.OffY + Scr->WBorBottom,
  294.                  
  295.                  WA_IDCMP,       LISTVIEWIDCMP | BUTTONIDCMP 
  296.                    | IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW 
  297.                    | IDCMP_VANILLAKEY,
  298.                  
  299.                  WA_Flags,       WFLG_DRAGBAR | WFLG_DEPTHGADGET 
  300.                    | WFLG_CLOSEGADGET | WFLG_SMART_REFRESH 
  301.                    | WFLG_ACTIVATE | WFLG_RMBTRAP,
  302.                  
  303.                  WA_Gadgets,     SFGList,
  304.                  WA_Title,       SFWdt,
  305.                  WA_ScreenTitle, ScrTitle,
  306.                  TAG_DONE )
  307.       ) == NULL)
  308.       return( -4 );
  309.  
  310.    GT_RefreshWindow( SFWnd, NULL );
  311.  
  312.    return( 0 );
  313. }
  314.  
  315. PRIVATE int SFVanillaKey( int whichkey )
  316. {
  317.    int rval = TRUE;
  318.    
  319.    switch (whichkey)
  320.       {
  321.       case 'c':
  322.       case 'C':
  323.       case 'x':
  324.       case 'X':
  325.       case 'q':
  326.       case 'Q':
  327.          rval = CancelClicked();
  328.          break;
  329.          
  330.       case 'u':
  331.       case 'U':
  332.          rval = UpdateClicked();
  333.  
  334.       default:
  335.          break;
  336.       }
  337.       
  338.    return( rval );
  339. }
  340.  
  341. PRIVATE int HandleSFIDCMP( void )
  342. {
  343.    struct IntuiMessage *m;
  344.    int                (*func)( int code );
  345.    BOOL                 running = TRUE;
  346.  
  347.    while (running == TRUE)
  348.       {
  349.       if ((m = GT_GetIMsg( SFWnd->UserPort )) == NULL)
  350.          {
  351.          (void) Wait( 1L << SFWnd->UserPort->mp_SigBit );
  352.          continue;
  353.          }
  354.  
  355.       CopyMem( (char *) m, (char *) &SFMsg, 
  356.                (long) sizeof( struct IntuiMessage )
  357.              );
  358.  
  359.       GT_ReplyIMsg( m );
  360.  
  361.       switch (SFMsg.Class)
  362.          {
  363.          case IDCMP_REFRESHWINDOW:
  364.             GT_BeginRefresh( SFWnd );
  365.             GT_EndRefresh( SFWnd, TRUE );
  366.             break;
  367.  
  368.          case IDCMP_CLOSEWINDOW:
  369.             running = SFCloseWindow();
  370.             break;
  371.  
  372.          case IDCMP_VANILLAKEY:
  373.             running = SFVanillaKey( SFMsg.Code );
  374.             break;
  375.             
  376.          case IDCMP_GADGETUP:
  377.          case IDCMP_GADGETDOWN:
  378.             func = (void *) ((struct Gadget *) SFMsg.IAddress)->UserData;
  379.  
  380.             if (func != NULL)
  381.                running = func( SFMsg.Code );
  382.  
  383.             break;
  384.          }
  385.       }
  386.  
  387.    return ( running );
  388. }
  389.  
  390. PUBLIC int HandleSysFont( void )
  391. {
  392.    if (OpenSFWindow() < 0)
  393.       {
  394.       }
  395.  
  396.    (void) HandleSFIDCMP();
  397.  
  398.    CloseSFWindow(); // Just in case.
  399.             
  400.    return( RETURN_OK );
  401. }
  402.  
  403. #ifdef DEBUG
  404.  
  405. PUBLIC int main( void )
  406. {
  407.    return( HandleSysFont() );
  408. }
  409.  
  410. #endif
  411.  
  412. /* ------------------- END of SysFonts.c file! -------------------- */
  413.